/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if (head == nullptr || head -> next == nullptr) return head;
        ListNode* t = nullptr;
        ListNode* inode;
        for(inode = head; inode -> next != nullptr;) {
            ListNode* n = inode -> next;
            inode -> next = t;
            t = inode;
            inode = n;
        }
        inode -> next = t;
        return inode;
    }
};